/* Molokai Theme for HyperMD Code Blocks in Obsidian */
/* 定义深色和浅色主题的变量 */
.theme-light {
    --code-block-background: #f5f5f5;  /* 浅灰色背景 */
    --code-block-foreground: #333333;  /* 深色文字 */
    --code-block-shadow: rgba(0, 0, 0, 0.1);
    --code-block-hover-background: #eaeaea;  /* 稍深的灰色用于悬停 */
    --code-block-comment: #998;  /* 注释颜色 */
    --code-block-keyword: #905;  /* 关键字颜色 */
    --code-block-string: #690;   /* 字符串颜色 */
    --code-block-number: #905;   /* 数字颜色 */
    --code-block-variable: #333; /* 变量颜色 */
    --code-block-operator: #9a6e3a; /* 操作符颜色 */
    --code-block-selection: #c2e0ff; /* 选中时背景颜色 */
}

.theme-dark {
    --code-block-background: #1E1F1C;
    --code-block-foreground: #F8F8F2;
    --code-block-shadow: rgba(0, 0, 0, 0.4);
    --code-block-hover-background: #2D2E23;
    --code-block-comment: #75715E;
    --code-block-keyword: #F92672;
    --code-block-string: #E6DB74;
    --code-block-number: #AE81FF;
    --code-block-variable: #F8F8F2;
    --code-block-operator: #F92672;
    --code-block-selection: #49483E;
}

/* 代码块容器 */
.markdown-preview-view pre,
.markdown-source-view.mod-cm6 .cm-line.HyperMD-codeblock {
    background-color: var(--code-block-background) !important;
}

/* 代码块选中样式 */
.markdown-source-view.mod-cm6 .cm-line.HyperMD-codeblock ::selection,
.markdown-preview-view pre[class*="language-"] code ::selection,
.HyperMD-codeblock-bg ::selection {
    background-color: var(--code-block-selection) !important;
    color: var(--code-block-foreground) !important;
}

/* 代码块内容 */
.markdown-preview-view code,
.markdown-source-view.mod-cm6 .cm-line.HyperMD-codeblock {
    color: var(--code-block-foreground) !important;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
}

/* 代码块行 */
.cm-line.HyperMD-codeblock {
    background-color: var(--code-block-background) !important;
}

/* 代码块围栏（```） */
.cm-formatting-code-block {
    color: var(--code-block-comment) !important;
}

/* 单个元素样式 */
.cm-def {
    color: var(--code-block-keyword) !important;
}

.cm-hmd-codeblock {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    color: var(--code-block-foreground) !important;
}

/* 代码块中的其他元素样式 */
.cm-hmd-codeblock.cm-keyword {
    color: var(--code-block-keyword) !important;
}

.cm-hmd-codeblock.cm-string {
    color: var(--code-block-string) !important;
}

.cm-hmd-codeblock.cm-number {
    color: var(--code-block-number) !important;
}

.cm-hmd-codeblock.cm-comment {
    color: var(--code-block-comment) !important;
}

.cm-hmd-codeblock.cm-variable {
    color: var(--code-block-foreground) !important;
}

.cm-hmd-codeblock.cm-operator {
    color: var(--code-block-operator) !important;
}

/* 代码块选中状态 */
.cm-hmd-codeblock::selection,
.HyperMD-codeblock ::selection {
    background-color: var(--code-block-background) !important;
}

/* 代码块hover效果 */
.cm-hmd-codeblock:hover,
.HyperMD-codeblock:hover {
    background-color: var(--code-block-hover-background) !important;
}

/* 代码块边框和圆角 */
/* .markdown-preview-view pre,
.markdown-source-view.mod-cm6 .cm-line.HyperMD-codeblock {
    border-radius: 4px;
    border: 1px solid #3E3D32 !important;
} */

/* 确保代码块内的行都有正确的背景色 */
.HyperMD-codeblock-bg {
    background-color: var(--code-block-background) !important;
}

/* 代码块的行号（如果启用） */
.cm-gutters {
    background-color: var(--code-block-background) !important;
    color: var(--code-block-comment) !important;
    border-right: 1px solid var(--code-block-shadow) !important;
}

.markdown-source-view.mod-cm6 .cm-line.HyperMD-codeblock .cm-cursor {
    border-left: 2px solid var(--code-block-foreground) !important; /* 亮色光标 */
}

.cm-secondaryCursor {
    border-left-color: var(--code-block-number) !important;
}

/* 光标颜色 */
.cm-line.HyperMD-codeblock {
    caret-color: var(--code-block-foreground) !important;
}

/* Molokai Theme for Inline Code */

/* 编辑模式下的 inline code 样式 */
.markdown-source-view.mod-cm6 .cm-inline-code {
    background-color: var(--code-block-background) !important;
    color: var(--code-block-foreground) !important;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    /* padding: 0.2em 0.4em; */
    /* border-radius: 3px; */
    font-size: 0.85em;
    caret-color: var(--code-block-foreground) !important;
}

/* 编辑模式下的 inline code 悬停效果 */
.markdown-source-view.mod-cm6 .cm-inline-code:hover {
    background-color: var(--code-block-hover-background) !important;
    transition: background-color 0.2s ease;
}

/* 确保 inline code 在行内正确对齐 */
:is(.markdown-preview-view, .markdown-rendered) code:not(pre code) {
    vertical-align: middle;
    line-height: normal;
}

/* 调整 inline code 在标题中的大小 */
:is(.markdown-preview-view, .markdown-rendered) h1 code:not(pre code),
:is(.markdown-preview-view, .markdown-rendered) h2 code:not(pre code),
:is(.markdown-preview-view, .markdown-rendered) h3 code:not(pre code),
:is(.markdown-preview-view, .markdown-rendered) h4 code:not(pre code),
:is(.markdown-preview-view, .markdown-rendered) h5 code:not(pre code),
:is(.markdown-preview-view, .markdown-rendered) h6 code:not(pre code) {
    font-size: 0.85em;
}